package com.lindroid.materialdesigndemo.tablayoutdemo;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.lindroid.materialdesigndemo.R;
import com.lindroid.materialdesigndemo.common.CommonAdapter;
import com.lindroid.materialdesigndemo.common.ViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * A simple {@link Fragment} subclass.
 * @author linyulong
 */
public class TabFragment extends Fragment {
    private List<String> titles = new ArrayList<>();
    private String title;


    @Bind(R.id.recycler_view)
    RecyclerView recyclerView;

    public TabFragment() {
        // Required empty public constructor
    }

    public TabFragment(String title) {
        this.title = title;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_tab, container, false);
        ButterKnife.bind(this, view);
        initData();
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
        recyclerView.addItemDecoration(new DividerItemDecoration(getActivity(),DividerItemDecoration.VERTICAL));
        recyclerView.setAdapter(new CommonAdapter<String>(getActivity(),R.layout.item_recycler,titles) {

            @Override
            protected void convert(ViewHolder holder, String s, int position) {
                holder.setText(R.id.text,titles.get(position));
            }
        });
        return view;
    }

    private void initData() {
        titles.clear();
        for (int i = 0; i < 30; i++) {
            titles.add(title + i);
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
